<template>
	<view>
		<switch :checked="checked" @change="change" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			checked:false,
		};
	},
	props: {
		list: {
			type: Array,
			default: () => []
		},
		keyName: {
			type: String,
			default: 'name'
		},
		idName: {
			type: String,
			default: 'id'
		},
		name: {
			type: String,
			default: ''
		},
		form: {
			type: Object,
			default: () => {}
		}
	},
	mounted() {
		// 需要在dom刷新完成之后进行默认值赋予, 不然会有问题
		this.$nextTick(function() {
			this.form.setValue(this.name, this.checked);
		});
	},
	methods: {
		change(e) {
			this.form.setValue(this.name, e.detail.value);
		}
	}
};
</script>

<style lang="scss" scoped>
.radioBox {
	width: 100%;
}
</style>
